#! /usr/bin/python

import os

filename = "README.md"
defaultMd = "defaultMD.md"
current_dir = os.path.join(os.getcwd(),"content")

def get_file_list(directory):
    file_list = os.listdir(directory)
    return file_list

def readfile():
    with open(defaultMd, 'r') as file:
        return file.read()

# 打开文件，选择写入模式（'w'）或追加模式（'a')
file = open(filename, 'w')
file.write(readfile())

for tmp in get_file_list(current_dir):
    strlist = []
    mdMuenList = os.path.join(current_dir,tmp)
    strlist.append("\n## "+tmp+"\n")
    xiangdu_dir = mdMuenList.replace(os.getcwd(),".")
    muenlist = os.listdir(mdMuenList)
    for oneFileName in muenlist:
        strlist.append("[{}]({}/{})\n\n".format(oneFileName,xiangdu_dir,oneFileName))
    # print(muenlist)

    file.writelines(strlist)

file.close
